import { AppDispatch } from '@/store/index';
import { getUserAPI, getUserProfileAPI, updatePhotoAPI, updateUserAPI } from '@/api/user';
import { UserType } from '../reducer/user';

export const getUserProfileAction = () => {
  return async (dispatch: AppDispatch) => {
    const res = await getUserProfileAPI();
    dispatch({ type: 'user/saveUserInfo', payload: res.data });
  };
};

export const getUserAction = () => {
  return async (dispatch: AppDispatch) => {
    const res = await getUserAPI();
    dispatch({ type: 'user/saveUser', payload: res.data });
  };
};

export const updatePhotoAction = (formData: FormData) => {
  return async () => {
    await updatePhotoAPI(formData);
  };
};

// 2
export const updateUserAction = (data: Partial<UserType>) => {
  return async () => {
    await updateUserAPI(data);
  };
};
